package com.example.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/repo")
public class RepoController {

    @PostMapping("/read")
    public SaResult readRepo() {
        boolean b = StpUtil.hasRoleOr("管理员", "开发者", "访客");
        if (b) {
            return SaResult.ok("可读仓库");
        }
        return SaResult.error("没有读仓库权限");
    }

    @PostMapping("/write")
    public SaResult writeRepo() {
        boolean b = StpUtil.hasRoleOr("管理员", "开发者");
        if (b) {
            return SaResult.ok("可写仓库");
        }
        return SaResult.error("没有写仓库权限");
    }

    @PostMapping("/delete")
    public SaResult deleteRepo() {
        boolean b = StpUtil.hasRoleOr("管理员");
        if (b) {
            return SaResult.ok("可删除仓库");
        }
        return SaResult.error("没有删除仓库权限");
    }
}
